package com.lipy.dubboconsumer.service;

import com.lipy.dubbocommon.entity.Staff;
import com.lipy.dubboconsumer.aop.MyCacheable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class MyCacheableService {

    @Autowired
    RedisTemplate<String,Object> redisTemplate;

//    @Autowired
//    RedisUtils redisUtils;

    @MyCacheable(key = "#staff.id")
    public Staff select(Staff staff){
        Staff staff1 = new Staff();
        BeanUtils.copyProperties(staff,staff1);
        staff1.setName(""+ System.currentTimeMillis());
        System.out.println("MyCacheableService.select "+staff1);
        return staff1;
    }
    @MyCacheable(key = "#id")
    public Staff select2(Integer id){
        Staff staff1 = new Staff();
        staff1.setId(id);
        staff1.setName(""+ System.currentTimeMillis());
        System.out.println("MyCacheableService.select2 "+staff1);
        return staff1;
    }
    @MyCacheable(key = "#staff.id",type = "insert")
    public Staff insert(Staff staff){
        System.out.println("MyCacheableService.insert "+staff);
        return staff;
    }
    @MyCacheable(key = "#staff.id",type = "update")
    public int update(Staff staff){
        staff.setName("update"+System.currentTimeMillis());
        System.out.println("MyCacheableService.update"+staff);
        return staff.getId();
    }

    @MyCacheable(key = "#id",type = "delete")
    public int delete(Integer id){
        System.out.println("MyCacheableService.delete"+id);
        return id;
    }
}
